<?php
class Admin_msgAction extends Action{
	function lists(){
		AdminAction::check();

		$user = D('msg');
		$count = $user->count();
		$pre_page = 10;
		$p=intval($_GET['p']);
		$p=$p==0 ? 1 : $p;
		$start=($p-1)*$pre_page;
		$list = $user->limit("$start,$pre_page")->findAll();
        
		import('ORG.Util.Page');
		$page = new Page($count,$pre_page);
		$pages = $page->show();
		$this->assign('pages',$pages);
		
		$this->assign('list',$list);
		$this->display('admin_msg@lists');
	}
	
	function post(){
		AdminAction::check();
		
		$get_id = $_GET['id'];
		$post_id = $_POST['id'];
		$hid = $_POST['hid'];
		
		if($hid==1){
			$arr['name'] = addslashes($_POST['name']);
			$arr['ip'] = addslashes($_POST['ip']);
			$arr['address'] = addslashes($_POST['address']);
			$arr['msg'] = addslashes($_POST['msg']);
			
			$user = D('msg');
			if($post_id>0){
				$re = $user->where('id='.$post_id)->save($arr);
			}else {
				$arr['send_time'] = time();
				$re = $user->add($arr);
			}
			if($re){
				go('/admin_msg/lists','操作成功!');
			}
		}
		if($get_id>0){
			$user = D('msg');
			$lab = $user->where('id='.$get_id)->find();
			$this->assign('lab',$lab);
		}
		$this->display('admin_msg@post');
	}
	
	function del(){
		$id = intval($_GET['id']);
		$user = D('msg');
		$re = $user->where('id='.$id)->delete();
		if($re){
			go('删除成功!','/admin_msg/lists');
		}
	}
}
?>